The getQuantity method returns the quantity for position.
var getQuantity();
This method returns a floating value representing quantity.
The following example demonstrates the use of getQuantity() method. The code attempts to close all long positions with quantity greater than 5000.
function start()
{
//close positions first
closeHugePositions();
//continue on...
}
function closeHugePositions()
{
//retrieve all long positions for current symbol
var positions = getAccount().getPositions(getSymbol(), POSITIONTYPE_LONG);
//if no long positions exist for current symbol, return
if(positions.length == 0)
return;
//loop through all positions, and close huge ones
for(var i = 0; i < positions.length; i++)
{
var position = positions[i];
if(position.getQuantity() > 5000)
{
//place sell order
account.placeMarketOrder(position.getSymbol(),
position.getQuantity(),
ACTIONTYPE_BUYTOCOVER,
TIFTYPE_GTC);
}
}
}
Copyright © 2006-2009 ActiveTick LLC